<template>
	<Layout>
		<template #title>律师列表</template>
		<ScrollRefresher @refresh="loadData">
			<view v-for="item of list" :key="item.id" class="lawyer-item">
				<view class="lawyer-item__icon aspect-fill">
					<image mode="aspectFill" :src="item.avatar"></image>
					<view class="online"></view>
				</view>
				<view class="lawyer-item__info">
					<view class="follow follow--highlight">咨询</view>
					<view class="lawyer-item__info__main">{{item.lawyerName}}</view>
					<view class="lawyer-item__info__desc">执业律师<text>|</text>执业{{item.practice}}年</view>
					<view class="lawyer-item__info__advantage">
						<view class="advantage-tag">擅长</view>
						<view class="advantage-list">
							<view class="ellipsis">{{item.special}}</view>
						</view>
					</view>
				</view>
			</view>

		</ScrollRefresher>
	</Layout>
</template>

<script setup lang="ts" name="LawLawyerList">
	import { onLoad, onPullDownRefresh } from '@dcloudio/uni-app';
	import { getLawyerListOfLaw } from '@/apis/lawfirm';
	import { ref } from 'vue';
	import type { AnyObj } from '@/types/global';

	let lawFirmId = '';
	const list = ref<AnyObj[]>([]);
	const lawFirmType = ref('1');

	function loadData() {
		getLawyerListOfLaw(lawFirmId).then((res) => {
			list.value = res.rows ?? [];
		});
	}


	onPullDownRefresh(() => {
		loadData();
		setTimeout(() => {
			uni.stopPullDownRefresh();
		}, 500);
	});

	onLoad((options) => {
		options = options as { lawFirmId : string; lawFirmType : string; }
		lawFirmId = options.lawFirmId;
		lawFirmType.value = options.lawFirmType;
		loadData();
	});
</script>